package com;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.connection.jdbconnection;

public class StudentSearch extends HttpServlet {

	
	
	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	@SuppressWarnings("null")
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
		response.setContentType("text/xml");
        HttpSession ses = request.getSession(true);
        PrintWriter out = response.getWriter();
        Statement st ;
        ResultSet rs ;
        Connection con = null;
        String name=request.getParameter("name");
        
        String course; 
        String sid ;
        String sname ;
        String fname ;
        String dob ;
        String gender ;
        String address ;
        String contact ;
        String emailid ;
        String issuedate ;
        String validuntill ;
      

       
        try {
            jdbconnection db=new jdbconnection();
            st=db.jdbConnection();
            String sql = "select * from studentform where student_id ='" + name +"' or course='"+ name +"'";
            System.out.println(sql);
            rs=st.executeQuery(sql);
            
            
            
            
         
            if (rs.next()) {

                         sid=rs.getString("student_id");
                         sname=rs.getString("sname");
                         fname=rs.getString("fname");
                         dob=rs.getString("dob");
                         gender=rs.getString("gender");
                         address=rs.getString("address");
                         contact=rs.getString("contact");
                         emailid=rs.getString("emailid");
                         course=rs.getString("course");
                         issuedate=rs.getString("issuedate");
                         validuntill=rs.getString("validuntile");
                         
                                            
                         System.out.println(sid);
                        System.out.println(sname);
                         
            request.getRequestDispatcher("SuccessfulSearch.jsp").forward(request, response);
            con.close();
            st.close();
            
            }

            else {
            	
            	request.getRequestDispatcher("NoSearch.jsp ").forward(request, response);
            
            }
            
        } catch (Exception e) {
        }
        
        }
        
       
		
		
		
	}


